package logic

import (
	"backend/apps/book/models"
	"context"
	"time"

	"backend/apps/book/proto"
	"backend/apps/book/rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateTagLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateTagLogic {
	return &CreateTagLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// CreateTag 标签相关操作
func (l *CreateTagLogic) CreateTag(in *proto.Tag) (*proto.CommonResponse, error) {
	now := time.Now().Unix()
	_, err := l.svcCtx.TagModel.Insert(l.ctx, &models.Tag{
		Name:       in.Name,
		CreateTime: now,
		UpdateTime: now,
	})
	return &proto.CommonResponse{}, err
}
